package com.telecom.cms.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.telecom.cms.dto.CustClu;
import com.telecom.cms.util.Constant;

public class CustCluDAO {
	Dao dao = new DaoImp();

	public List findAll() {

		String sql = "select * from " + Constant.CUST_CLU;

		List list = new ArrayList();
		try {
			ResultSet rs = dao.select(sql);
			while (rs.next()) {
				CustClu sd = new CustClu();
				sd.setLatnId(rs.getInt(1));
				sd.setCustCluId(rs.getInt(2));
				sd.setCustCluName(rs.getString(3));
				sd.setCustCluDesc(rs.getString(4));
				sd.setPrdNbr(rs.getLong(5));
				sd.setUserId(rs.getString(6));
				sd.setCreateTime(rs.getString(7));
				sd.setAppSubjectId(rs.getInt(8));
				sd.setClustertype(rs.getString(9));
				list.add(sd);
			}
			if (rs != null) {

				rs.close();
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			dao.closeconn();
		}
		return list;

	}

	public List findAll(String latnid, String clutype) {

		String sql = "select * from " + Constant.CUST_CLU + "  where latn_id='"
				+ latnid + "' and cluster_type=" + clutype;

		List list = new ArrayList();
		try {
			ResultSet rs = dao.select(sql);
			while (rs.next()) {
				CustClu sd = new CustClu();
				sd.setLatnId(rs.getInt(1));
				sd.setCustCluId(rs.getInt(2));
				sd.setCustCluName(rs.getString(3));
				sd.setCustCluDesc(rs.getString(4));
				sd.setPrdNbr(rs.getLong(5));
				sd.setUserId(rs.getString(6));
				sd.setCreateTime(rs.getString(7));
				sd.setAppSubjectId(rs.getInt(8));
				sd.setClustertype(rs.getString(9));
				list.add(sd);
			}
			if (rs != null) {

				rs.close();
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			dao.closeconn();
		}
		return list;

	}
	
	public List findAll(String latn_id,int APP_SUBJECT_ID) {

		String sql = "select * from " + Constant.CUST_CLU + "  where latn_id='"
				+ latn_id + "' and APP_SUBJECT_ID=" + APP_SUBJECT_ID;
		ResultSet rs = null;
		List list = new ArrayList();
		try {

			rs = dao.select(sql);
			while (rs.next()) {
				CustClu dto = new CustClu();
				dto.setLatnId(rs.getInt("LATN_ID"));
				dto.setCustCluId(rs.getInt("CUST_CLU_ID"));
				dto.setCustCluName(rs.getString("CUST_CLU_NAME"));
				dto.setPrdNbr(rs.getLong("PRD_NBR"));
				dto.setCreateTime(rs.getString("CREATE_TIME"));
				list.add(dto);
			}

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if(rs !=null){
					rs.close();
				}
	
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
	
	

}
